package com.unitTest;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

import com.acmetelecom.BillGenerator;
import com.acmetelecom.BillingSystem;
import com.acmetelecom.CallEvent;
import com.acmetelecom.HtmlPrinter;

public class BillingSystemTest {
	//@Rule public final JUnitRuleMockery context = new JUnitRuleMockery();
	
	//BillingSystem bl = context.mock(BillingSystem.class);
	BillingSystem bl = new BillingSystem(new BillGenerator(HtmlPrinter.getInstance()));

	@Test
	public void testCallInitiatedStringString() {
		
		bl.callInitiated("caller", "callee");
		Class b = BillingSystem.class;
		
		try{
			Field f = b.getDeclaredField("callLog");
			f.setAccessible(true);
			System.out.println("123");
			System.out.println(f.get(bl));
			f.setAccessible(false);
			Assert.assertNotNull(f.get(bl));
		}
		catch(Exception e){
			e.printStackTrace();
		}	
	}

	@Test
	public void testCallCompletedStringString() {
		bl.callCompleted("caller", "callee");
		Class b = BillingSystem.class;
		
		try{
			Field f = b.getDeclaredField("callLog");
			f.setAccessible(true);
			System.out.println("123");
			System.out.println(f.get(bl));
			f.setAccessible(false);
			Assert.assertNotNull(f.get(bl));
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

	@Test
	public void testCreateCustomerBills() {
		bl.callInitiated("caller", "callee");
		bl.callCompleted("caller", "callee");
		bl.createCustomerBills();
		Class b = BillingSystem.class;
		List<CallEvent> empty = new ArrayList<CallEvent>();
		
		try{
			Field f = b.getDeclaredField("callLog");
			f.setAccessible(true);
			System.out.println("123");
			System.out.println(f.get(bl));
			f.setAccessible(false);
			Assert.assertEquals(empty,f.get(bl));
			
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
